package cn.strive.eams.bus.service.impl;


import cn.strive.eams.bus.mapper.BusMapper;
import cn.strive.eams.bus.pojo.dto.BusQuery;
import cn.strive.eams.bus.pojo.dto.BusSaveParam;
import cn.strive.eams.bus.pojo.entity.Bus;
import cn.strive.eams.bus.pojo.vo.BusVO;
import cn.strive.eams.bus.service.BusService;
import cn.strive.eams.virtual.pojo.entity.Virtual;
import cn.strive.eams.virtual.pojo.vo.VirtualVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.PrintStream;
import java.util.Date;
import java.util.List;

import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;

@Service
@Slf4j
public class BusServiceImpl implements BusService {

    @Autowired
    BusMapper busMapper;

    @Override
    public List<BusVO> selectBus(BusQuery busQuery) {
        log.debug("查询校车业务:busQuery={}",busQuery);
        List<BusVO> list = busMapper.selectBus(busQuery);
        return list;
    }

    @Override
    public void saveBus(BusSaveParam busSaveParam) {
        log.debug("保存校车:busSaveParam={}",busSaveParam);
        Bus bus = new Bus();
        BeanUtils.copyProperties(busSaveParam,bus);
        if (bus.getId() == null){
            bus.setCreateTime(new Date());
            busMapper.insert(bus);
        }else {
            bus.setUpdateTime(new Date());
            busMapper.update(bus);
        }
    }

    @Override
    public void updateStatus(Long id, String status) {
        log.debug("更新校车状态:id={},status={}", id, status);
        Bus bus = new Bus();
        bus.setId(id);
        bus.setStatus(status);
        busMapper.update(bus);
    }

    @Override
    public void deleteVirtual(Long id) {
        log.debug("删除校车:id={}",id);
        busMapper.deleteBus(id);
    }

    @Override
    public void deleteBatch(List<Long> ids) {
        log.debug("批量删除校车:ids={}", ids);
        for (Long id : ids){
            busMapper.deleteBus(id);
        }
    }
}
